/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('speechfiletranscriberlite', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model GetTaskResultRequest {
  debug?: boolean(name='Debug'),
  taskId?: string(name='TaskId'),
}

model GetTaskResultResponseBody = {
  bizDuration?: int32(name='BizDuration'),
  recDuration?: int32(name='RecDuration'),
  requestId?: string(name='RequestId'),
  result?: {
    paragraphs?: [ 
      {
        beginTIme?: long(name='BeginTIme'),
        channelId?: long(name='ChannelId'),
        endTime?: long(name='EndTime'),
        text?: string(name='Text'),
      }
    ](name='Paragraphs'),
    sentences?: [ 
      {
        beginTime?: long(name='BeginTime'),
        channelId?: long(name='ChannelId'),
        emotionValue?: float(name='EmotionValue'),
        endTime?: long(name='EndTime'),
        silenceDuration?: int32(name='SilenceDuration'),
        speakerId?: string(name='SpeakerId'),
        speechRate?: int32(name='SpeechRate'),
        text?: string(name='Text'),
      }
    ](name='Sentences'),
    words?: [ 
      {
        beginTime?: long(name='BeginTime'),
        channelId?: long(name='ChannelId'),
        endTime?: long(name='EndTime'),
        word?: string(name='Word'),
      }
    ](name='Words'),
  }(name='Result'),
  solveTime?: long(name='SolveTime'),
  statusCode?: long(name='StatusCode'),
  statusText?: string(name='StatusText'),
  taskId?: string(name='TaskId'),
}

model GetTaskResultResponse = {
  headers: map[string]string(name='headers'),
  body: GetTaskResultResponseBody(name='body'),
}

async function getTaskResultWithOptions(request: GetTaskResultRequest, runtime: Util.RuntimeOptions): GetTaskResultResponse {
  Util.validateModel(request);
  var query = OpenApiUtil.query(Util.toMap(request));
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetTaskResult',
    version = '2021-12-21',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'GET',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getTaskResult(request: GetTaskResultRequest): GetTaskResultResponse {
  var runtime = new Util.RuntimeOptions{};
  return getTaskResultWithOptions(request, runtime);
}

model SubmitTaskRequest {
  debug?: boolean(name='Debug'),
  task?: string(name='Task'),
}

model SubmitTaskResponseBody = {
  requestId?: string(name='RequestId'),
  statusCode?: long(name='StatusCode'),
  statusText?: string(name='StatusText'),
  taskId?: string(name='TaskId'),
}

model SubmitTaskResponse = {
  headers: map[string]string(name='headers'),
  body: SubmitTaskResponseBody(name='body'),
}

async function submitTaskWithOptions(request: SubmitTaskRequest, runtime: Util.RuntimeOptions): SubmitTaskResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.debug)) {
    query['Debug'] = request.debug;
  }
  if (!Util.isUnset(request.task)) {
    query['Task'] = request.task;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'SubmitTask',
    version = '2021-12-21',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function submitTask(request: SubmitTaskRequest): SubmitTaskResponse {
  var runtime = new Util.RuntimeOptions{};
  return submitTaskWithOptions(request, runtime);
}

